package com.novel.utils;

import java.text.DecimalFormat;

/**
 * 数字格式化
 * 把比较大的数字转换为比较短的字符串，并在后面添加对应的单位
 */
public class NumFormatUtils {

    private static final DecimalFormat df = new DecimalFormat("######0.00");


    public static String parseNumber(long num) {
        if (num > 10000 && num < 100000000) {
            return df.format(num / 10000d) + "万";
        } else if (num > 100000000) {
            return df.format(num / 100000000d) + "亿";
        }
        return num + "";
    }

    public static String parseNumber(int num) {
        if (num > 10000 && num < 100000000) {
            return df.format(num / 10000d) + "万";
        } else if (num > 100000000) {
            return df.format(num / 100000000d) + "亿";
        }
        return num + "";
    }

    public static String parseNumber(double num) {
        if (num > 10000 && num < 100000000) {
            return df.format(num / 10000d) + "万";
        } else if (num > 100000000) {
            return df.format(num / 100000000d) + "亿";
        }
        return num + "";
    }

    public static String parseNumber(float num) {
        if (num > 10000 && num < 100000000) {
            return df.format(num / 10000d) + "万";
        } else if (num > 100000000) {
            return df.format(num / 100000000d) + "亿";
        }
        return num + "";
    }

}